#ifndef _MESSAGEHEADER_HPP_
#define _MESSAGEHEADER_HPP_

#include "jhdefs.hpp"
#include "net/NameValueCollection.hpp"
#include <ostream>
#include <istream>
#include <vector>

NET_NAMESPACE_BEGIN

//RFC 2822
class CMessageHeader : public CNameValueCollection
{
public:
	CMessageHeader();
	CMessageHeader(const CMessageHeader& messageHeader);
	virtual ~CMessageHeader();
	CMessageHeader& operator = (const CMessageHeader& messageHeader);

	virtual void write(std::ostream& ostr) const;
	virtual void read(std::istream& istr);

	int getFieldLimit() const;
	void setFieldLimit(int limit);
	bool hasToken(const std::string& fieldName, const std::string& token) const;

	static void splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty = true);
	static void splitParameters(const std::string& s, std::string& value, CNameValueCollection& parameters);
	static void splitParameters(const std::string::const_iterator& begin, const std::string::const_iterator& end, CNameValueCollection& parameters);
	static void quote(const std::string& value, std::string& result, bool allowSpace = false);

private:
	enum Limits
	{
		MAX_NAME_LENGTH  = 256,
		MAX_VALUE_LENGTH = 8192,
		DFL_FIELD_LIMIT  = 100
	};

	int m_fieldLimit;
};

NET_NAMESPACE_END

#endif
